package com.example.demo.common;

import com.example.demo.entity.UserInfo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UserSessionTools {
    /**
     * 获取当前登录用户
     *
     * @param request
     * @return
     */
    public static UserInfo getLoginUser(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        if (session != null && session.getAttribute(ApplicationVariable.SESSION_KEY_USERINFO) != null) {
            return (UserInfo) session.getAttribute(ApplicationVariable.SESSION_KEY_USERINFO);
        }
        return null;
    }
}